<?php
namespace Home\Controller;
use Think\Controller;
class SearchController extends CommonController {
    public function index(){
    	$words = I('get.q');

    	// 加入头文件
		// require '/path/to/pscws4.class.php';

		Vendor("pscws4.pscws4",'','.class.php');

		// 建立分词类对像, 参数为字符集, 默认为 gbk, 可在后面调用 set_charset 改变
		$pscws = new \PSCWS4('utf8');


		$pscws->set_dict('./Public/dict.utf8.xdb');


		$pscws->send_text($words);

		$tops = $pscws->get_tops(3, 'n,v');

		$sql = "select * from question where ";
		
		foreach ($tops as $row) {
			$sql .=" title like '%".$row['word']."%' or"; 
		}

		$sql = rtrim($sql,'or');

		$question = M()->query($sql);

		$this->assign('question',$question);

		$this->display();
		
    }
}